package com.youens.navigationdrawertest.ui.favorite

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.youens.navigationdrawertest.R


class RecordAdapter(var list:List<Record>,var context:Context) : BaseAdapter() {
    inner class ViewHolder(){
        lateinit var word: TextView
        lateinit var translate:TextView
    }

    override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
        var viewHoler: ViewHolder ?= null
        var view:View ?= null
        if(p1==null){
            viewHoler = ViewHolder()
            view = LayoutInflater.from(context).inflate(R.layout.item_record, null)
            viewHoler.word = view.findViewById(R.id.textView_word)
            viewHoler.translate = view.findViewById(R.id.textView_translate)
            view.tag = viewHoler
        }else{
            view = p1
            viewHoler = view.tag as ViewHolder
        }

        viewHoler.word.text = list.get(p0).word
        viewHoler.translate.text = list.get(p0).translate
        return view!!
    }

    override fun getItem(p0: Int): Any {
        return list.get(p0)
    }

    override fun getItemId(p0: Int): Long {
        return p0.toLong()
    }

    override fun getCount(): Int {
        return list.size
    }
}